package org.csc.sss.datacore.primary.model;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.csc.sss.datacore.config.ValidateConfig;
import org.hibernate.annotations.GenericGenerator;
import org.springframework.data.annotation.CreatedBy;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedBy;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
import java.util.Date;

@Data
@Entity
@Table(name="person")
@EntityListeners(AuditingEntityListener.class)
public class Person {

	@Id
	@GenericGenerator(name="pk_uuid", strategy="uuid")
	@GeneratedValue(generator="pk_uuid")
	private String id;


	@Column(name="type")
	@ApiModelProperty("类型")
	private Integer type;

	@Column(name="name")
	private String name;

	@Column(name="age")
	@NotNull(message = "年龄不能为空", groups = {ValidateConfig.Person.ADD.class})
	private Integer age;

	@Column(name="address")
	private String address;

	@Column(name="state")
	private Boolean state;

	@ManyToOne(targetEntity=SysUser.class,fetch=FetchType.LAZY)
	@JoinColumn(name="create_by")
	@CreatedBy
	private SysUser createBy;

	@ManyToOne(targetEntity=SysUser.class,fetch=FetchType.LAZY)
	@JoinColumn(name="last_modified_by")
	@LastModifiedBy
	private SysUser lastModifiedBy;

	@Column(name = "create_time")
	@CreatedDate
	private Date createTime;

	@Column(name = "last_modified_time")
	@LastModifiedDate
	private Date lastModifiedTime;

	public static final String ID = "id";
	public static final String TYPE = "type";
	public static final String NAME = "name";
	public static final String ADDRESS = "address";
	public static final String STATE = "state";
	public static final String AGE = "age";
	public static final String LAST_MODIFIED_BY = "lastModifiedBy";
	public static final String CREATE_BY = "createBy";
	public static final String CREATE_TIME = "createTime";
	public static final String LAST_MODIFIED_TIME = "lastModifiedTime";

}
